package com.fyzk.activity.user;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.fyzk.activity.fragment.TransformFragment;
import com.fyzk.activity.fragment.WithdrawCashFragment;
import com.fyzk.activity.news.BaseFragmentAdapter;
import com.fyzk.activity.user.accountdetail.WithDrawRecordActivity;
import com.fyzk.base.BaseActivity;
import com.fyzk.utils.DensityUtils;
import com.fyzk.utils.IntentParamUtils;
import com.fyzk.view.TopTitleView;
import com.tyjc.lottery.R;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *
 * @author 指尖沙漏
 * @mood
 * @description
 * @date 2019/9/23 15:53
 * </p>
 */
@ContentView(R.layout.activity_withdraw)
public class WithdrawActivity extends BaseActivity {
    private Context context = this;

    @ViewInject(R.id.withdrawUI_topTitleView)
    private TopTitleView topView;
    @ViewInject(R.id.withdrawUI_tabLayout)
    private TabLayout mTabLayout;
    @ViewInject(R.id.withdrawUI_viewPager)
    private ViewPager mViewPager;
    private int type; // 0提现 1转存
    private List<Fragment> mFragments;
    private String[] mTitles = {"提现"};
    private String[] mTitlesCaijin = {"转存"};

    private String userName;
    private String realName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initViews();
        initData();
    }

    @Override
    public void initViews() {
        userName = getIntent().getStringExtra(IntentParamUtils.USERNAME);
        realName = getIntent().getStringExtra(IntentParamUtils.REALNAME);
        type = getIntent().getIntExtra(IntentParamUtils.TYPE_GUOGUAN, 0);

        topView.setOnTitleClickListener(this);

        mFragments = new ArrayList<>();
        if (type == 0) {
            WithdrawCashFragment fragment1 = WithdrawCashFragment.newInstance(userName, realName);
            mFragments.add(fragment1);
        } else {
            TransformFragment fragment2 = TransformFragment.newInstance(userName);
            mFragments.add(fragment2);
            topView.setRightTxtVisible(View.GONE);
            topView.setCenterText("转存");
        }

        BaseFragmentAdapter adapter = new BaseFragmentAdapter(getSupportFragmentManager(), mFragments, type == 0 ? mTitles : mTitlesCaijin);
        mViewPager.setAdapter(adapter);
        mTabLayout.setupWithViewPager(mViewPager);
    }

    @Override
    public void onRightClick() {
        Intent intent = new Intent(context, WithDrawRecordActivity.class);
        startActivity(intent);
    }

    private void initData() {
//        mTabLayout.post(new Runnable() {
//            @Override
//            public void run() {
//                DensityUtils.setIndicator(mTabLayout, 20, 20);
//            }
//        });
    }

}
